import {CHAMGE_INPUT_VALUE,DELECTE_ITEM,ADD_ITEM,INIT_DATA_INFO} from './actionType';
const defaultState = {
    inputValue:"",
    list:[]
};
export default (state=defaultState,action)=>{
    if(action.type===CHAMGE_INPUT_VALUE){
        const newSate = JSON.parse(JSON.stringify(state));
        newSate.inputValue =action.value; 
        return newSate;
    }
    if(action.type===ADD_ITEM){
        const newSate = JSON.parse(JSON.stringify(state));
        newSate.inputValue ="";
        newSate.list =[...newSate.list,state.inputValue];
        return newSate;
    }
    if(action.type===DELECTE_ITEM){
        const newSate = JSON.parse(JSON.stringify(state));
        const list = [...newSate.list];
        list.splice(action.value,1);
        newSate.list =list;
        return newSate;
    }
    if(action.type===INIT_DATA_INFO){
        const newSate = JSON.parse(JSON.stringify(state));
        const list = [...newSate.list,...action.value];
        newSate.list =list;
        return newSate;
    }
    return state
}